using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace MonoCash.ObjectModel
{
    class Security : ObjectModel
    {
        public class PriceCollection : List<Price>
        {
            private int SecurityID = -1;
            public PriceCollection(int id)
                : base()
            {
                SecurityID = id;
            }
            public new void Add(Price item)
            {
                item.SecurityID = SecurityID;
                base.Add(item);
            }
            public void Add(DateTime date, Decimal price)
            {
                Price p = new Price();
                p.SecurityID = SecurityID;
                p.Date = date;
                p.LastPrice = price;
                base.Add(p);
            }
            public new void Remove(Price item)
            {
                base.Remove(item);
                item.Delete();
            }
        }

        public Security() : base()
        {

        }
        public Security(object objectId) : base(objectId)
        {
            
        }
        public PriceCollection Prices
        {
            get { return new PriceCollection(ID); }
        }
        public static List<Security> Securities
        {
            get
            {
                List<Security> temp = new List<Security>();
                foreach (DataRow row in Program.AppSettings.Data.Securities.Rows)
                {
                    temp.Add(new Security(int.Parse(row["ID"].ToString())));
                }
                return temp;
            }
        }
        private string symbol;

        public string Symbol
        {
            get { return symbol; }
            set { symbol = value; SyncToBackend(); }
        }
        private string description;

        public string Description
        {
            get { return description; }
            set { description = value; SyncToBackend(); }
        }

        public Currency Currency
        {
            get { return new Currency(CurrencyID); }
            set { CurrencyID = value.ID; }
        }

        private int currencyID = int.Parse(Program.AppSettings.DefaultCurrencyID);
        public int CurrencyID
        {
            get { return currencyID; }
            set { currencyID = value; SyncToBackend(); }
        }

        private decimal valuationFactor = 1;

        public decimal ValuationFactor
        {
            get { return valuationFactor; }
            set { valuationFactor = value; SyncToBackend(); }
        }
	

        private bool downloadPrices = false;
        public bool DownloadPrices
        {
            get { return downloadPrices; }
            set { downloadPrices = value; SyncToBackend(); }
        }
	
	
    }
}
